package net.qhzw.vip.qiyu.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import net.qhzw.vip.qiyu.entity.DtsUser;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.MallUserVipService;
import net.qhzw.vip.qiyu.util.PageParam;
import net.qhzw.vip.qiyu.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 商场用户管理
 */
@RestController
@RequestMapping("/user")
public class MallUserController {

    @Autowired
    private MallUserVipService mallUserVipService;

    /**
     * 设置VIP
     * @param userId
     * @return
     */
    @PostMapping("/setVip/{userId}")
    public JsonResult setVip(@PathVariable Long userId){
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        int count = mallUserVipService.selectUserVip(userId, shopId);
        if (count > 0){
            mallUserVipService.del(userId, shopId);
        }else {
            mallUserVipService.setVIP(userId, shopId);
        }
        return JsonResult.ok();
    }


    @GetMapping("page")
    public JsonResult findByPage(PageParam<DtsUser> page, String name, Integer isVip){
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        IPage<DtsUser> mallUserVipIPage = mallUserVipService.findByPage(shopId, page, name, isVip);
        return JsonResult.ok(mallUserVipIPage);
    }



}
